﻿using System;

namespace Medianamik.Core
{
    //Pratique pour mixer différents éléments (propriétés hétérogènes) dans une même structure
    public abstract class Entity<T> : IEntity, IEquatable<T> 
        where T : IEntity
    {
        protected Entity()
        {
            ID = Guid.NewGuid();
            Status = EntityStates.New;
        }

        protected Entity(Guid id)
        {
            ID = id;
            Status = EntityStates.Loaded;
        }

        public Guid ID { get; protected set; }

        public virtual bool Equals(T other)
        {
            if (ReferenceEquals(null, other)) return false;
            if (ReferenceEquals(this, other)) return true;
            return other.ID.Equals(ID);
        }

        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj)) return false;
            if (ReferenceEquals(this, obj)) return true;
            if (obj.GetType() != typeof(T)) return false;
            return Equals((T)obj);
        }

        public override int GetHashCode()
        {
            return ID.GetHashCode();
        }

        public EntityStates Status { get; set; }
    }
}
